<?php

namespace common\models\actor;

use common\helpers\ArrayHelper;
use Yii;

/**
 * This is the model class for table "{{%actor}}".
 *
 * @property int $id
 * @property int $user_id 用户ID
 * @property string $name 真实姓名
 * @property int $gender 性别:0未知，1男，2女
 * @property string $birthday 出生日期
 * @property string $contact 联系方式
 * @property string $avatar 头照
 * @property string $location 当前所在地
 * @property int $index 推荐指数
 * @property int $weight 权重
 * @property int $listorder 排序：由小及大
 * @property int $status 简历状态
 * @property int $created_at 创建时间
 * @property int $updated_at 更新时间
 * @property int $deleted_at 删除时间
 */
class Actor extends \common\db\ActiveRecord {

    use \common\traits\Constants;

    const STATUS_ACTIVE = 10;
    const STATUS_DEFAULT = 0;

    public $tagnames;

    /**
     * {@inheritdoc}
     */
    public static function tableName() {
        return '{{%actor}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['user_id', 'gender', 'index', 'weight', 'listorder', 'status', 'created_at', 'updated_at', 'deleted_at'], 'integer'],
            [['name', 'avatar'], 'required'],
            [['birthday', 'contact'], 'safe'],
            [['name', 'location'], 'string', 'max' => 50],
            [['avatar'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'user_id' => '用户ID',
            'name' => '真实姓名',
            'gender' => '性别:0未知，1男，2女',
            'birthday' => '出生日期',
            'contact' => '联系方式',
            'avatar' => '头照',
            'location' => '当前所在地',
            'index' => '推荐指数',
            'weight' => '权重',
            'listorder' => '排序：由小及大',
            'status' => '简历状态',
            'created_at' => '创建时间',
            'updated_at' => '更新时间',
            'deleted_at' => '删除时间',
        ];
    }

    public function getActorTags() {
        return $this->hasMany(ActorTag::class, ['actor_id' => 'id']);
    }

    public function getTags() {
        return $this->hasMany(ActorTag::class, ['actor_id' => 'id']);
    }

    public function getTagNames() {
        return $this->tags? ArrayHelper::getColumn($this->tags,'text'):[];
    }

    public function fields() {
        return [
            'id',
            'user_id',
            'name',
            'gender',
            'birthday',
            'contact',
            'avatar',
            'location',
        ];
    }

}
